var express = require('express');
var router = express.Router();

/* GET users listing. */
router.get('/logout', function(req, res) {
  req.session.loginname = undefined;
   res.redirect("back");
});
var users = {}

router.post("/login", function(req, res) {
  const {loginname,password} = req.body;
  if (users[loginname] &&users[loginname].password === password) {
    req.session.loginname = loginname;
  }
  res.redirect("back");
});


router.post("/reg", function(req, res) {
  const {loginname,password,confirm} = req.body;
  if (loginname && password && password === confirm) {
    users[loginname] = {loginname,password};
  }
  res.redirect("back");
})



module.exports = router;
